const useSelectStore = defineStore("select", {
  state: () => ({
    select: new Array(),
  }),
  actions: {
    // 获取选项
    getSelect(_key) {
      if (_key == null && _key == "") {
        return null;
      }
      try {
        for (let i = 0; i < this.select.length; i++) {
          if (this.select[i].key == _key) {
            return this.select[i].value;
          }
        }
      } catch (e) {
        return null;
      }
    },
    // 设置选项
    setSelect(_key, value) {
      if (_key !== null && _key !== "") {
        this.select.push({
          key: _key,
          value: value,
        });
      }
    },
    // 删除选项
    removeSelect(_key) {
      var bln = false;
      try {
        for (let i = 0; i < this.select.length; i++) {
          if (this.select[i].key == _key) {
            this.select.splice(i, 1);
            return true;
          }
        }
      } catch (e) {
        bln = false;
      }
      return bln;
    },
    // 清空选项
    cleanSelect() {
      this.select = new Array();
    },
    // 初始选项
    initSelect() {},
  },
});

export default useSelectStore;
